public class LeetCode345 {

    public static void main(String[] args) {
        LeetCode345 leetCode345 = new LeetCode345();
        System.out.println(leetCode345.reverseVowels("ai"));
    }

    public String reverseVowels(String s) {
        char[] data = s.toCharArray();
        int length = s.length();
        int startIndex = 0;
        int endIndex = length - 1;

        while (startIndex < endIndex){
            while (startIndex < endIndex && !isVoVal(data[startIndex])){
                startIndex++;
            }

            while (endIndex > startIndex && !isVoVal(data[endIndex])){
                endIndex--;
            }

            swap(data, startIndex, endIndex);
            startIndex++;
            endIndex--;
        }

        return new String(data);
    }

    public boolean isVoVal(char value){
        return "aeiouAEIOU".indexOf(value) >= 0;
    }

    public void swap(char[] data, int i, int j){
        char temp = data[i];
        data[i] = data[j];
        data[j] = temp;
    }
}
